package com.hospital.hospitalsystem.modules.doctor.controller;

import com.hospital.hospitalsystem.base.BaseResponse;
import com.hospital.hospitalsystem.config.TokenVerify;
import com.hospital.hospitalsystem.modules.doctor.biz.DoctorBiz;
import com.hospital.hospitalsystem.modules.doctor.dto.BookRecordReq;
import com.hospital.hospitalsystem.modules.doctor.dto.BookRecordRsp;
import com.hospital.hospitalsystem.modules.doctor.dto.MessageBookUuidReq;
import com.hospital.hospitalsystem.utils.LoginUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author qiancheng
 * @date 2023/4/27
 */
@RestController
@RequestMapping("/book-record")
@Api(tags = "诊疗记录管理")
@Validated
public class BookRecordController {

    @Autowired
    private DoctorBiz doctorBiz;

    @Autowired
    private LoginUtils loginUtils;

    @ApiOperation(value = "根据bookUuid获取诊疗记录")
    @RequestMapping(path = "/record-bookUuid-get",method = RequestMethod.POST)
    @TokenVerify(type = "doctor,user")
    public BaseResponse recordBookUuid(@RequestBody MessageBookUuidReq req){
        String role = loginUtils.getUser().getRoles();
        BookRecordRsp result = doctorBiz.recordBookUuid(req);
        if (role.equals("user")) {
            if (result.getDoctorStatus() == 2) {
                result.setDoctorDescription(null);
            }
            if (result.getUserStatus() == 2) {
                result.setUserDescription(null);
            }
        }
        return BaseResponse.success(result);
    }

    @ApiOperation(value = "根据bookUuid修改诊疗记录")
    @RequestMapping(path = "/record-bookUuid-update",method = RequestMethod.POST)
    @TokenVerify(type = "doctor")
    public BaseResponse recordBookUuidUpdate(@RequestBody BookRecordReq req){
        doctorBiz.recordBookUuidUpdate(req);
        return BaseResponse.success();
    }

    @ApiOperation(value = "根据bookUuid增加诊疗记录")
    @RequestMapping(path = "/record-bookUuid-add",method = RequestMethod.POST)
    @TokenVerify(type = "doctor")
    public BaseResponse recordBookUuidAdd(@RequestBody BookRecordReq req){
        doctorBiz.recordBookUuidAdd(req);
        return BaseResponse.success();
    }

    @ApiOperation(value = "根据bookUuid删除诊疗记录")
    @RequestMapping(path = "/record-bookUuid-delete",method = RequestMethod.POST)
    @TokenVerify(type = "doctor")
    public BaseResponse recordBookUuidDelete(@RequestBody BookRecordReq req){
        doctorBiz.recordBookUuidDelete(req);
        return BaseResponse.success();
    }
}
